package com.hb.utils;

import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;
import cn.hutool.crypto.digest.HMac;

import static cn.hutool.crypto.digest.HmacAlgorithm.HmacMD5;

public class RsaUtil {

	/**
	 * 对password原文进行Hmac加密
	 * encrypt
	 */
	public static String encryptHMacDgestHex(String userName, String password) {
		HMac hMac = new HMac(HmacMD5, userName.getBytes());
		return hMac.digestHex(password);
	}

	/**
	 * 解密
	 */
	public static String decrypt(RSA rsa, String password) {
		return rsa.decryptStr(password, KeyType.PrivateKey);
	}

	/**
	 * 拿到用户名和加密密码返回HMac字符串
	 */
	public static String getHMacDgestHex(RSA rsa, String userName, String password) {
		return encryptHMacDgestHex(userName, decrypt(rsa, password));
	}

	public static void main(String[] args) {
		String s = encryptHMacDgestHex("test", "123456");
		System.out.println("s = " + s);
	}


}
